<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>文章列表--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<!--查询条件-->
<div class="layui-collapse" id="search">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form" >
		    <div class="layui-form-item layui-row">
		        <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">结算单编号</label>
                	<div class="layui-input-block">
                		<input type="text" name="closeNum" class="layui-input searchVal" placeholder="请输入结算单编号" />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">结算单名称</label>
                	<div class="layui-input-block">
                		<input type="text" name="closeName" class="layui-input searchVal" placeholder="请输入结算单名称" />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">结算单状态</label>
                	<div class="layui-input-block">
                	    <select name="closeState" id="closeState" lay-filter="closeState" >
                            <option>请选择结算单状态：</option>
                		</select>
                	</div>
                </div>
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">结算时间</label>
                	<div class="layui-input-inline">
                		<input type="text" class="layui-input" name="startTime" id="startTime" placeholder="yyyy-MM-dd">
                	</div>
                	<label class="layui-form-label" style="width: 5px">-</label>
                	<div class="layui-input-inline">
                    	<input type="text" class="layui-input" name="endTime" id="endTime" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-block layui-col-md3">
                    <label class="layui-form-label">医院名称</label>
                	<div class="layui-input-block">
                		<input type="text" name="hospitalName" readonly id="hname" class="layui-input searchVal" placeholder="请输入医院名称" />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                  <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">查询</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
              </div>
		</form>
	</blockquote>
</div>
<!--数据表格-->
<div>
    <table class="layui-hide" id="closeTable" lay-filter="closeTable"></table>
    <div id="toolBars" style="display: none">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加</button>
    </div>
    <div id="rowBars" style="display: none">
        <button type="button" lay-event="show" class="layui-btn layui-btn-sm layui-btn-warm"><span class="layui-icon layui-icon-search"></span>查看</button>
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm layui-bg-green"><span class="layui-icon layui-icon-edit"></span>修改</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
    </div>
</div>
<!--添加修改弹出层-->
<div id="addOrUpdate" style="display: none">
    <form class="layui-form" id="addOrUpdateTable" lay-filter="addOrUpdateTable">
	    <div class="layui-form-item">
	        <div class="layui-inline ">
                <label class="layui-form-label">医院编号</label>
            	<div class="layui-input-inline">
            	    <input type="hidden" name="id">
            		<input type="text" name="hospitalId" id="hospitalId" class="layui-input searchVal" readonly />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">医院名称</label>
            	<div class="layui-input-inline">
            		<input type="text" name="hospitalName" id="hospitalName" class="layui-input searchVal" readonly />
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">结算单编号</label>
            	<div class="layui-input-inline">
            	    <input name="closeNum" class="layui-input searchVal" id="closeNum" readonly />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">结算单名称</label>
            	<div class="layui-input-inline" style="width: 300px;">
            	    <input name="closeName" readonly class="layui-input searchVal" lay-verify="required" id="closeName" placeholder="请输入结算单名称" >
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">结算时间</label>
            	<div class="layui-input-inline">
            		<input type="text" class="layui-input createTime" name="createTime" lay-verify="required" readonly placeholder="yyyy-MM-dd">
            	</div>
            </div>
            <div class="layui-inline ">
            	<label class="layui-form-label">建单时间</label>
            	<div class="layui-input-inline">
                	<input type="text" class="layui-input" name="createTime" lay-verify="required" readonly id="overTime" placeholder="yyyy-MM-dd">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">联系人</label>
            	<div class="layui-input-inline">
            		<input type="text" name="linkman" class="layui-input searchVal" placeholder="请输入联系人" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">联系电话</label>
            	<div class="layui-input-inline">
            		<input type="text" name="linkphone" lay-verify="required|phone" class="layui-input searchVal" placeholder="请输入联系电话" />
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">结算单状态</label>
            	<div class="layui-input-inline">
            		<select name="closeState" id="closeSta" lay-filter="closeSta">
                        <option>请选择采购状态：</option>
                    </select>
            	    <div class="mydiv" title="不可修改" style="position:absolute;width: 100%;height: 100%;left: 0px;top: 0px;background: #fff;opacity: 0;filter:alpha(opacity=0)"></div>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">提交时间</label>
            	<div class="layui-input-inline">
            		<input type="text" name="submitTime" readonly class="layui-input searchVal" placeholder="yyyy-MM-dd" />
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-block ">
                <label class="layui-form-label">备注</label>
            	<div class="layui-input-block" style="width: 515px">
            		<input type="text" name="remark" class="layui-input searchVal" placeholder="请输入备注" />
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                  <button type="submit" class="layui-btn" lay-submit="" id="doSubmit" lay-filter="doSubmit">提交</button>
                </div>
            </div>
        </div>
	</form>
</div>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script>
    layui.use(['form','laydate','element','layer','jquery','table'],function(){
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var date = new Date();
        laydate.render({
          elem: '#startTime'
          ,type: 'datetime'
        });
        laydate.render({
          elem: '#endTime'
          ,type: 'datetime'
        });
        var hospitalId;
        $.ajax({
            url:"/getSessionUnitId",
            dataType:"json",
            type:"post",
            async:false,
            success:function(data) {
                hospitalId = data;
            }
        })
        if(hospitalId!=null&&hospitalId!=undefined){
            $.post("/hospital/getHospitalById",{id:hospitalId},function(data) {
                $("#hname").val(data.hospitalName);
            })
        }
        var tableIns = table.render({
            elem:"#closeTable",
            url:"/hospitalClose/loadAllClose",
            where:{hospitalId:hospitalId},
            toolbar:"#toolBars",
            page:true,
            height:'full-290',
            cols:[
                [
                    {type:'checkbox',fixed:'center'}
                    ,{field:'id', title:'ID',  fixed: 'left', unresize: true,width:'80' ,sort: true,align:'center'}
                    ,{field:'hospitalName', title:'医院名称',align:'center',width:'180',templet:function(res) {
                        return $("#hname").val();
                    }}
                    ,{field:'closeNum', title:'结算单编号',align:'center',width:'150'}
                    ,{field:'closeName', title:'结算单名称',align:'center',width:'150'}
                    ,{field:'createTime', title:'结算时间',align:'center',width:'180',templet:function(res) {
                        return res.createTime==null?"":res.createTime.substring(0,10);
                    }}
                    ,{field:'closeState', title:'结算单状态',align:'center',width:'180',templet:function(res) {
                        return res.closeState==null?"":res.closeState==1?"未确认结算":res.closeState==2?"已确认结算":"";
                    }}
                    ,{field:'createTime', title:'建单时间',align:'center',width:'180',templet:function(res) {
                        return res.createTime==null?"":res.createTime.substring(0,10);
                    }}
                    ,{field:'recentTime', title:'最近修改时间',align:'center',width:'180'}
                    ,{field:'submitTime', title:'提交时间',align:'center',width:'180'}
                    ,{fixed: 'right', title:'操作', toolbar: '#rowBars',width:260}
                ]
            ]
        })
        //表单提交
        form.on("submit(sub)",function(data) {
            tableIns.reload({
                where:data.field
            })
            return false;
        })
        //下拉框渲染
        select($("#closeState"),"/getDataDictionary?dataType=6");
        var mainIns;
        var url;
        //监听头部工具栏事件
        table.on('toolbar(closeTable)',function(obj) {
            switch (obj.event) {
                case 'add':
                    openAdd();
            }
        })
        //监听行工具栏事件
        table.on('tool(closeTable)',function(obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'show':
                    openShow(data);
                    break;
                case 'update':
                    openUpdate(data);
                    break;
                case 'delete':
                    openDelete(data);
            }
        })
        //提交表单
        form.on('submit(doSubmit)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //提示信息
                layer.msg(data.msg);
                //关闭弹出层
                layer.close(mainIns);
                //重新渲染table
                tableIns.reload();
                //跳转到采购维护
                if(url=="/hospitalClose/add"&&data.code==200){
                    $.post("/hospitalClose/getNewHospitalCloseId",function(id) {
                        window.location.href = "/toCloseMaintain?id="+id;
                    })
                }
            })
            return false;
        })
        //打开添加弹出层
        function openAdd() {
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['800px','450px'],
                title:"添加结算单",
                success:function(layero,index) {
                    //更改url
                    url = "/hospitalClose/add";

                    var date = new Date();//当前时间
                    //时间添值
                    var createTime = date.getFullYear()+"-"+("0"+(date.getMonth()+1)).slice(-2)+"-"+("0"+date.getDate()).slice(-2)/*+" "+("0"+date.getHours()).slice(-2)+":"+("0"+date.getMinutes()).slice(-2)+":"+("0"+date.getSeconds()).slice(-2)*/;
                    //清空添加表单
                    $("#addOrUpdateTable")[0].reset();
                    //根据单位id查询医院信息
                    if(hospitalId>0){
                        $("#hospitalId").val(hospitalId);
                        $("#hospitalName").val($("#hname").val());
                        $("#closeName").val($("#hname").val()+createTime+"结算单");
                    }
                    $(".createTime").val(createTime);
                    $("#overTime").val(createTime);
                    //渲染下拉框
                    select($("#closeSta"),"/getPurchaseState",1);
                    $("input[name='linkman']").attr("readonly",false);
                    $("input[name='linkphone']").attr("readonly",false);
                    $("input[name='remark']").attr("readonly",false);
                    $("button[type='submit']").show();
                    $("#showDataDrugForm").hide();
                    $("#doSubmit").show();
                }
            })
        }
        //打开查看弹出层
        function openShow(data) {
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['800px','450px'],
                title:"查看结算单",
                success:function(index) {
                    $("#showDataDrugForm").hide();
                    form.val("addOrUpdateTable",data);
                    select($("#closeSta"),"/getPurchaseState",data.closeState);
                    $("input[name='linkman']").attr("readonly",true);
                    $("input[name='linkphone']").attr("readonly",true);
                    $("input[name='remark']").attr("readonly",true);
                    $("#hospitalName").val($("#hname").val());
                    $("#doSubmit").hide();
                }
            })
        }
        //打开修改弹出层
        function openUpdate(data) {
            window.location.href = "/toCloseMaintain?id="+data.id;
        }
        //打开删除弹出层
        function openDelete(data) {
            mainIns = layer.confirm('您真的要删除吗？', {
                btn: ['删除','取消'] //按钮
            }, function(){
                $.post("/close/delete",{id:data.id},function(res) {
                    layer.msg(res.msg);
                    table.reload();
                })
            })
        }
        //下拉框渲染
        function select(item,url,dataNum) {
            $.get(url,function(data) {
                var html = "<option value='0'>请选择结算单状态：</option>";
                $.each(data.data,function(index,item) {
                    if(item.dataNum===dataNum){
                        html += "<option selected value='"+item.dataNum+"'>"+item.dataName+"</option>"
                    }else {
                        html += "<option value='"+item.dataNum+"'>"+item.dataName+"</option>"
                    }
                })
                item.empty();
                item.append(html);
                // $("#closeState").html(html);
                form.render();
            })
        }
    })
</script>
</body>
</html>